﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Transactions;

public partial class Main_ServiceInvoice_TDSManagement : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    List<string> ControlCounter;
    List<string> DdlParticularID;
    List<string> DdlServiceID;
    List<string> TxtNewBalAmountID;
    List<string> TxtNewTdsAmountID;
    List<string> TxtNewStRateID;
    List<string> TxtNewPeCessRateID;
    List<string> TxtNewHeCessRateID;
    List<string> TxtNewServiceTaxID;
    List<string> TxtNewPeCessID;
    List<string> TxtNewHeCessID;
    List<string> TxtNewCertificateNoID;
    List<string> TxtNewReceivedDateID;
    List<string> CalReceivedDateID;
    List<string> TxtNewRemarksID;
    List<string> hidReferenceID;
    List<string> hidRefTranID;
    List<string> hidRefChildID;
    List<string> hidAddDescID;
    int rowcount = 1;


    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        OverrideAddMORE();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initialize();
            fillTDSNo();
            BindCustomer();
            BindCustomerReceipt();
            TxtDate.Text = DateTime.Now.ToShortDateString();
            txtrecdate.Text = DateTime.Now.ToShortDateString();
            hidDate.Value = TxtDate.Text;
            if (Request.QueryString["status"] != null)
            {
                if (Request.QueryString["status"].ToString() == "insert")
                {
                    lblMsg.Text = "Inserted Successfully !";
                }
                else
                {
                    lblMsg.Text = string.Empty;
                }
            }
            else
            {
                lblMsg.Text = string.Empty;
            }

           fillEmptyRow();

           ddlparticular1.Width = Unit.Pixel(75);
           ddlservice1.Width = Unit.Pixel(75);
        }
    }

    protected void initialize()
    {
        ControlCounter = new List<string>();
        ViewState["ControlCounter"] = ControlCounter;

        DdlParticularID = new List<string>();
        ViewState["DdlParticularID"] = DdlParticularID;

        DdlServiceID = new List<string>();
        ViewState["DdlServiceID"] = DdlServiceID;

        TxtNewBalAmountID = new List<string>();
        ViewState["TxtNewBalAmountID"] = TxtNewBalAmountID;

        TxtNewTdsAmountID = new List<string>();
        ViewState["TxtNewTdsAmountID"] = TxtNewTdsAmountID;

        TxtNewStRateID = new List<string>();
        ViewState["TxtNewStRateID"] = TxtNewStRateID;

        TxtNewPeCessRateID = new List<string>();
        ViewState["TxtNewPeCessRateID"] = TxtNewPeCessRateID;

        TxtNewHeCessRateID = new List<string>();
        ViewState["TxtNewHeCessRateID"] = TxtNewHeCessRateID;

        TxtNewServiceTaxID = new List<string>();
        ViewState["TxtNewServiceTaxID"] = TxtNewServiceTaxID;

        TxtNewPeCessID = new List<string>();
        ViewState["TxtNewPeCessID"] = TxtNewPeCessID;

        TxtNewHeCessID = new List<string>();
        ViewState["TxtNewHeCessID"] = TxtNewHeCessID;

        TxtNewCertificateNoID = new List<string>();
        ViewState["TxtNewCertificateNoID"] = TxtNewCertificateNoID;

        TxtNewReceivedDateID = new List<string>();
        ViewState["TxtNewReceivedDateID"] = TxtNewReceivedDateID;

        CalReceivedDateID = new List<string>();
        ViewState["CalReceivedDateID"] = CalReceivedDateID;

        TxtNewRemarksID = new List<string>();
        ViewState["TxtNewRemarksID"] = TxtNewRemarksID;

        hidReferenceID = new List<string>();
        ViewState["hidReferenceID"] = hidReferenceID;

        hidRefTranID = new List<string>();
        ViewState["hidRefTranID"] = hidRefTranID;

        hidRefChildID = new List<string>();
        ViewState["hidRefChildID"] = hidRefChildID;

        hidAddDescID = new List<string>();
        ViewState["hidAddDescID"] = hidAddDescID;

    }

    

    protected void fillTDSNo()
    {
        /* Last Tds no. selection from Tdsmanagement_Main (To show in text box with increament of one) */

        string strsql = "select Max(TDSMANAGEMENTID) as tdsno from IVC_TDSMANAGEMENT_MAIN";
        DataTable dt = DU.getdata(strsql);
        string chkval = dt.Rows[0]["tdsno"].ToString();
        if (chkval == "")
        {
            chkval = "0";
        }
        TxtTdsNo.Text = (Convert.ToInt32(chkval) + 1).ToString();
        Txtrectdsno.Text = (Convert.ToInt32(chkval) + 1).ToString();
    }

    private DataTable _GetBilledServiceTaxRate(string strTranId)
    {
        /* To get services which have been billed */
        DataTable DTServiceTax = new DataTable();
        if (strTranId != string.Empty)
        {
            SqlParameter[] sparam ={                                  
                                   new SqlParameter("@TRAINID",strTranId)
                               };
            DTServiceTax = DU.getdatausingprocedure("USP_IVC_GetTransactionServiceRates", sparam);
        }
        return DTServiceTax;
    }
    private DataTable _ReturnParticular()
    {
        /* To return all particulars for services. */

        string strTranDate = string.Empty;
        string strDate = TxtDate.Text; //hidDate.Value.ToString();
        DataTable DTParticular = new DataTable();
        if (strDate != string.Empty)
        {
            string[] str = strDate.Split('/');
            strTranDate = str[1] + "/" + str[0] + "/" + str[2];
        }
        if (ddlCustomer.SelectedValue != "0" && strTranDate != string.Empty)
        {
            SqlParameter[] sparam ={
                                   new SqlParameter("@LID",ddlCustomer.SelectedValue),
                                   new SqlParameter("@VOUDATE",strTranDate),
                                   new SqlParameter("@FINYEAR",Session["FINYEAR"].ToString()),
                                   new SqlParameter("@CURRENTTRANID","0"),
                                   new SqlParameter("@ISSALESRETURN","0")
                                   };
            DTParticular = DU.getdatausingprocedure("USP_IVC_GetPendingParticulars", sparam);
        }
        return DTParticular;
    }
    private DataTable _ReturnPendingService_Details()
    {
        /* To get all pending services */

        string strTranDate = string.Empty;
        string strDate = TxtDate.Text.Trim(); 
        DataTable DTServiceDetails = new DataTable();
        if (strDate != string.Empty)
        {
            string[] str = strDate.Split('/');
            strTranDate = str[1] + "/" + str[0] + "/" + str[2];
        }
        if (ddlCustomer.SelectedValue != "0" && strTranDate != string.Empty)
        {
            SqlParameter[] sparam ={
                                   new SqlParameter("@CUSTOMERLEDGERID",ddlCustomer.SelectedValue),
                                   new SqlParameter("@VOUDATE",strTranDate),                                   
                                   new SqlParameter("@TRANID","0"),
                                   new SqlParameter("@ISSALESRETURN","0")
                               };
            DTServiceDetails = DU.getdatausingprocedure("USP_IVC_GetAllPendingServiceDetails", sparam);
        }
        return DTServiceDetails;
    }
    protected void BindCustomer()
    {
        /* To select all customer */

        DataTable DTCutomer = DU.getdatausingprocedure("USP_IVC_GetCustomerLedger");
        if (DTCutomer.Rows.Count > 0)
        {
            ddlCustomer.DataSource = DTCutomer;
            ddlCustomer.DataTextField = "LNAME";
            ddlCustomer.DataValueField = "LID";
            ddlCustomer.DataBind();

            ListItem li = new ListItem("--- Select Customer ---", "0");
            li.Selected = true;
            ddlCustomer.Items.Insert(0, li);
        }
    }
    protected void BindCustomerReceipt()
    {
        /* To bind customer names with DDL in Receipt/CreditNote tab. */

        DataTable DTCutomer = DU.getdatausingprocedure("USP_IVC_GetCustomerLedger");
        if (DTCutomer.Rows.Count > 0)
        {
            ddlreccustomer.DataSource = DTCutomer;
            ddlreccustomer.DataTextField = "LNAME";
            ddlreccustomer.DataValueField = "LID";
            ddlreccustomer.DataBind();

            ListItem li = new ListItem("--- Select Customer ---", "0");
            li.Selected = true;
            ddlreccustomer.Items.Insert(0, li);
        }
    }
    protected void FillGridForDetail()
    {
        /* To fill gridview in Receipt/CreditNote tab according to selected customer name */

        SqlParameter[] sqlpara =
        {
            new SqlParameter("@CUSTOMERLEDGERID",ddlreccustomer.SelectedValue)
        };
        DataTable dtDetail = DU.getdatausingprocedure("USP_IVC_GetExistingTDS", sqlpara);
            grdDetailExistingTDS.DataSource = dtDetail;
            grdDetailExistingTDS.DataBind();
     }
    protected void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
    {
        /* To fill particulars related with selected customer */
        if (ddlCustomer.SelectedValue != "0")
        {
            /* to remove all old existing rows in tblParticularService */
            int count = Convert.ToInt32(hidControlCounter.Value.ToString());
            for (int i = count; i >1; i--)
            {
                if (tblParticularService.Rows.Count > 1 && i > 1)
                {
                    tblParticularService.Rows.RemoveAt(i);
                }
            }

            hidControlCounter.Value = "1".ToString();
            rowcount = 1;
            initialize();

            BindParticulars((DropDownList)tblParticularService.Rows[1].FindControl("ddlparticular1"));

            ddlservice1.Items.Clear();
            hidRefTranId1.Value = "";
            hidRefTranId1.Value = "";
            hidRefChildId1.Value = "";
            hidAddDesc1.Value = "";
            txtnewbalamount1.Text = "";
            txtnewtdsamount1.Text = "";
            txtnewstrate1.Text = "";
            txtnewpecessrate1.Text = "";
            txtnewhecessrate1.Text = "";
            txtnewservicetax1.Text = "";
            txtnewpecess1.Text = "";
            txtnewhecess1.Text = "";
            txtnewcertificateno1.Text = "";
            txtnewreceiveddate1.Text = "";
            txtnewremarks1.Text = "";
        }
    }
    protected void BindParticulars(DropDownList ddl)
    {
        /* To bind related (with customer name) particular with DDL */

        if (ddlCustomer.SelectedValue != "0")
        {
            DataTable dtParticular = _ReturnParticular();
            if (dtParticular.Rows.Count > 0)
            {
                ddl.DataSource = dtParticular;
                ddl.DataTextField = "Reference";
                ddl.DataValueField = "ReferenceId";
                ddl.DataBind();
                ListItem li = new ListItem("--- Select Particulars ---", "0");
                li.Selected = true;
                ddl.Items.Insert(0, li);
              }
            else
            {
             ddl.Items.Clear();
            }
        }
    }
    protected void BindService(DropDownList ddlService)
    {

    }
    protected void TxtDate_TextChanged(object sender, EventArgs e)
    {
      
    }
   
    protected void ddlparticular_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowIndex = Convert.ToInt32(ddl.ID.ToString().Substring(13));
        DataTable DTParticular = _ReturnParticular();
        DataTable DTService = _ReturnPendingService_Details();
        DropDownList ddlServices = (DropDownList)tblParticularService.Rows[rowIndex].FindControl("ddlService" + rowIndex);
        HiddenField hidReferenceId = (HiddenField)tblParticularService.Rows[rowIndex].FindControl("hidReferenceId" + rowIndex);
        TextBox txtSTRate = (TextBox)tblParticularService.Rows[rowIndex].FindControl("txtnewstrate" + rowIndex);
        TextBox txtPECessRate = (TextBox)tblParticularService.Rows[rowIndex].FindControl("txtnewpecessrate" + rowIndex);
        TextBox txtHECessRate = (TextBox)tblParticularService.Rows[rowIndex].FindControl("txtnewhecessrate" + rowIndex);

        if (ddl.SelectedValue != "0")
        {
            DataView DVParticular = DTParticular.DefaultView;
            DVParticular.RowFilter = "ReferenceId='" + ddl.SelectedValue + "'";
            DataTable DTTempParticular = DVParticular.ToTable();

            DataTable DTServiceTaxRate = _GetBilledServiceTaxRate(DTTempParticular.Rows[0]["TransactionID"].ToString());
            if (DTServiceTaxRate.Rows.Count > 0)
            {
                txtSTRate.Text = DTServiceTaxRate.Rows[0]["SERVICETAXRATE"].ToString();
                txtPECessRate.Text = DTServiceTaxRate.Rows[0]["EDUCESS1RATE"].ToString();
                txtHECessRate.Text = DTServiceTaxRate.Rows[0]["EDUCESS2RATE"].ToString();
            }
            else
            {
                txtSTRate.Text = "0";
                txtPECessRate.Text = "0";
                txtHECessRate.Text = "0";
            }

            DataView DVService = DTService.DefaultView;
            DVService.RowFilter = "ReferenceSerial='" + ddl.SelectedValue + "'";
            DataTable DTTempService = DVService.ToTable();
            if (DTTempService.Rows.Count > 0)
            {
                ddlServices.DataSource = DTTempService;
                ddlServices.DataTextField = "ServiceName";
                ddlServices.DataValueField = "ServiceId";
                ddlServices.DataBind();
                ddlServices.Items.Insert(0, new ListItem("-Select-", "0"));
            }
            else
            {
                ddlServices.Items.Clear();
                ddlServices.Items.Insert(0, new ListItem("", "0"));
            }

            hidReferenceId.Value = DTParticular.Rows[0]["ReferenceID"].ToString();
          }
        else
        {
            ddlServices.Items.Clear();
            ddlServices.Items.Insert(0, new ListItem("", "0"));
            hidReferenceId.Value = "";
        }

    }
    protected void ddlservice_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowIndex = Convert.ToInt32(ddl.ID.ToString().Substring(10));
        DataTable DTService = _ReturnPendingService_Details();
        HiddenField hidRefTranid = (HiddenField)tblParticularService.Rows[rowIndex].FindControl("hidRefTranId" + rowIndex);
        HiddenField hidRefChildId = (HiddenField)tblParticularService.Rows[rowIndex].FindControl("hidRefChildId" + rowIndex);
        HtmlInputHidden hidRefAddDesc = (HtmlInputHidden)tblParticularService.Rows[rowIndex].FindControl("hidAddDesc" + rowIndex);
        DropDownList ddlparticular = (DropDownList)tblParticularService.Rows[rowIndex].FindControl("ddlparticular" + rowIndex);
        TextBox txtnewbalamount = (TextBox)tblParticularService.Rows[rowcount].FindControl("txtnewbalamount" + rowIndex);
        TextBox txtSTRate = (TextBox)tblParticularService.Rows[rowIndex].FindControl("txtnewstrate" + rowIndex);
        TextBox txtPECessRate = (TextBox)tblParticularService.Rows[rowIndex].FindControl("txtnewpecessrate" + rowIndex);
        TextBox txtHECessRate = (TextBox)tblParticularService.Rows[rowIndex].FindControl("txtnewhecessrate" + rowIndex);

        string strgettaxable = "select taxability from IVC_SERVICEMASTER where SERVICEID=" + ddl.SelectedValue + "";
        DataTable dtTaxability = DU.getdata(strgettaxable);
        
        if (dtTaxability.Rows.Count > 0)
        {
            hidRefAddDesc.Value = dtTaxability.Rows[0]["taxability"].ToString();
        
        }

        if (ddl.SelectedValue != "0")
        {
            DataView DVService = new DataView();
            DVService = DTService.DefaultView;
            DVService.RowFilter = "ReferenceSerial='" + ddlparticular.SelectedValue + "' and ServiceId='" + ddl.SelectedValue + "'";
            DataTable DTServiceTaxRate = DVService.ToTable();
            DataTable DTServiceCessRate = new DataTable();
            if (DTServiceTaxRate.Rows.Count > 0)
            {
                DTServiceCessRate = _GetBilledServiceTaxRate(DTServiceTaxRate.Rows[0]["TranID"].ToString());
            }
            if (DTServiceCessRate.Rows.Count > 0)
            {
                txtnewbalamount.Text = Math.Round(Convert.ToDecimal(DTServiceTaxRate.Rows[0]["PENDINGAMOUNT"].ToString()), 2).ToString();
                txtSTRate.Text = DTServiceCessRate.Rows[0]["SERVICETAXRATE"].ToString();
                txtPECessRate.Text = DTServiceCessRate.Rows[0]["EDUCESS1RATE"].ToString();
                txtHECessRate.Text = DTServiceCessRate.Rows[0]["EDUCESS2RATE"].ToString();
            }
            if (DTService.Rows.Count > 0)
            {
                hidRefTranid.Value = DTService.Rows[0]["TranID"].ToString();
                hidRefChildId.Value = DTService.Rows[0]["ChildID"].ToString();
            }
        }
        else
        {
            txtSTRate.Text = "";
            txtPECessRate.Text = "";
            txtHECessRate.Text = "";
        }

    }

    protected void fillEmptyRow()
    {
        int countRow = tblParticularService.Rows.Count;
        if (countRow < 12)
        {
            int loopcount = 12 - countRow;
            for (int i = 0; i < loopcount; i++)
            {
                HtmlTableRow row = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                HtmlTableCell cell2 = new HtmlTableCell();
                HtmlTableCell cell3 = new HtmlTableCell();
                HtmlTableCell cell4 = new HtmlTableCell();
                HtmlTableCell cell5 = new HtmlTableCell();
                HtmlTableCell cell6 = new HtmlTableCell();
                HtmlTableCell cell7 = new HtmlTableCell();
                HtmlTableCell cell8 = new HtmlTableCell();
                HtmlTableCell cell9 = new HtmlTableCell();
                HtmlTableCell cell10 = new HtmlTableCell();
                HtmlTableCell cell11 = new HtmlTableCell();
                HtmlTableCell cell12 = new HtmlTableCell();
                HtmlTableCell cell13 = new HtmlTableCell();

                cell1.InnerHtml = "&nbsp;";
                cell2.InnerHtml = "&nbsp;";
                cell3.InnerHtml = "&nbsp;";
                cell4.InnerHtml = "&nbsp;";
                cell5.InnerHtml = "&nbsp;";
                cell6.InnerHtml = "&nbsp;";
                cell7.InnerHtml = "&nbsp;";
                cell8.InnerHtml = "&nbsp;";
                cell9.InnerHtml = "&nbsp;";
                cell10.InnerHtml = "&nbsp;";
                cell11.InnerHtml = "&nbsp;";
                cell12.InnerHtml = "&nbsp;";
                cell13.InnerHtml = "&nbsp;";

                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                row.Cells.Add(cell3);
                row.Cells.Add(cell4);
                row.Cells.Add(cell5);
                row.Cells.Add(cell6);
                row.Cells.Add(cell7);
                row.Cells.Add(cell8);
                row.Cells.Add(cell9);
                row.Cells.Add(cell10);
                row.Cells.Add(cell11);
                row.Cells.Add(cell12);
                row.Cells.Add(cell13);
                tblParticularService.Rows.Add(row);
            }
        }
    }

    protected void OverrideAddMORE()
    {
        ControlCounter = (List<string>)ViewState["ControlCounter"];
        DdlParticularID = (List<string>)ViewState["DdlParticularID"];
        DdlServiceID = (List<string>)ViewState["DdlServiceID"];
        TxtNewBalAmountID = (List<string>)ViewState["TxtNewBalAmountID"];
        TxtNewTdsAmountID = (List<string>)ViewState["TxtNewTdsAmountID"];
        TxtNewStRateID = (List<string>)ViewState["TxtNewStRateID"];
        TxtNewPeCessRateID = (List<string>)ViewState["TxtNewPeCessRateID"];
        TxtNewHeCessRateID = (List<string>)ViewState["TxtNewHeCessRateID"];
        TxtNewServiceTaxID = (List<string>)ViewState["TxtNewServiceTaxID"];
        TxtNewPeCessID = (List<string>)ViewState["TxtNewPeCessID"];
        TxtNewHeCessID = (List<string>)ViewState["TxtNewHeCessID"];
        TxtNewCertificateNoID = (List<string>)ViewState["TxtNewCertificateNoID"];
        TxtNewReceivedDateID = (List<string>)ViewState["TxtNewReceivedDateID"];
        CalReceivedDateID = (List<string>)ViewState["CalReceivedDateID"];
        TxtNewRemarksID = (List<string>)ViewState["TxtNewRemarksID"];
        hidRefTranID = (List<string>)ViewState["hidRefTranID"];
        hidRefChildID = (List<string>)ViewState["hidRefChildID"];
        hidAddDescID = (List<string>)ViewState["hidAddDescID"];
        hidReferenceID = (List<string>)ViewState["hidReferenceID"];

        if (ControlCounter != null)
        {
            int tempcounter = Convert.ToInt32(ControlCounter.Count);
            for (int i = 0; i < tempcounter; i++)
            {
                rowcount++;

                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "top";

                DropDownList ddlparticular = new DropDownList();
                ddlparticular.ID = DdlParticularID[i].ToString();
                ddlparticular.CssClass = "dropdown";
                ddlparticular.AutoPostBack = true;
               // ddlparticular.Width = Unit.Pixel(75); 
                BindParticulars(ddlparticular);
                ddlparticular.SelectedIndexChanged += new EventHandler(ddlparticular_SelectedIndexChanged);
                cell1.Controls.Add(ddlparticular);

                HiddenField hidReferenceId = new HiddenField();
                hidReferenceId.ID = hidReferenceID[i].ToString();
                cell1.Controls.Add(hidReferenceId);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "top";

                DropDownList ddlservice = new DropDownList();
                ddlservice.ID = DdlServiceID[i].ToString();
                ddlservice.AutoPostBack = true;
                //ddlservice.Width = Unit.Pixel(75);
                ddlservice.CssClass = "dropdown";

                ddlservice.Attributes.Add("onchange", "return checkItemRepetion(this.id);");
                ddlservice.SelectedIndexChanged += new EventHandler(ddlservice_SelectedIndexChanged);
                cell2.Controls.Add(ddlservice);

                HiddenField hidRefTranId = new HiddenField();
                hidRefTranId.ID = hidRefTranID[i].ToString();
                cell2.Controls.Add(hidRefTranId);

                HiddenField hidRefChildId = new HiddenField();
                hidRefChildId.ID = hidRefChildID[i].ToString();
                cell2.Controls.Add(hidRefChildId);

                HtmlInputHidden hidAddDesc = new HtmlInputHidden();
                hidAddDesc.ID = hidAddDescID[i].ToString();
                cell2.Controls.Add(hidAddDesc);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "top";

                TextBox txtnewbalamount = new TextBox();
                txtnewbalamount.ID = TxtNewBalAmountID[i].ToString();
                txtnewbalamount.CssClass = "inputnumber";
                txtnewbalamount.Enabled = false;
                cell3.Controls.Add(txtnewbalamount);

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "top";

                TextBox txtnewtdsamount = new TextBox();
                txtnewtdsamount.ID = TxtNewTdsAmountID[i].ToString();
                txtnewtdsamount.Attributes.Add("OnKeyPress", "return isNumberKey(this.id, event); checkserviceselect(this.id);");
                txtnewtdsamount.Attributes.Add("onblur","calculate(); calculateTotalAmount();");
                txtnewtdsamount.CssClass = "inputnumber";
                txtnewtdsamount.Text = "0.00";
                cell4.Controls.Add(txtnewtdsamount);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "top";

                TextBox txtnewstrate = new TextBox();
                txtnewstrate.ID = TxtNewStRateID[i].ToString();
                txtnewstrate.CssClass = "inputnumber";
                txtnewstrate.Enabled = false;
                cell5.Controls.Add(txtnewstrate);

                HtmlTableCell cell6 = new HtmlTableCell();
                cell6.Align = "top";

                TextBox txtnewpecessrate = new TextBox();
                txtnewpecessrate.ID = TxtNewPeCessRateID[i].ToString();
                txtnewpecessrate.CssClass = "inputnumber";
                txtnewpecessrate.Enabled = false;
                cell6.Controls.Add(txtnewpecessrate);

                HtmlTableCell cell7 = new HtmlTableCell();
                cell7.Align = "top";

                TextBox txtnewhecessrate = new TextBox();
                txtnewhecessrate.ID = TxtNewHeCessRateID[i].ToString();
                txtnewhecessrate.CssClass = "inputnumber";
                txtnewhecessrate.Enabled = false;
                cell7.Controls.Add(txtnewhecessrate);

                HtmlTableCell cell8 = new HtmlTableCell();
                cell8.Align = "top";

                TextBox txtnewservicetax = new TextBox();
                txtnewservicetax.ID = TxtNewServiceTaxID[i].ToString();
                txtnewservicetax.CssClass = "inputnumber";
                txtnewservicetax.Enabled = false;
                cell8.Controls.Add(txtnewservicetax);

                HtmlTableCell cell9 = new HtmlTableCell();
                cell9.Align = "top";

                TextBox txtnewpecess = new TextBox();
                txtnewpecess.ID = TxtNewPeCessID[i].ToString();
                txtnewpecess.CssClass = "inputnumber";
                txtnewpecess.Enabled = false;
                cell9.Controls.Add(txtnewpecess);

                HtmlTableCell cell10 = new HtmlTableCell();
                cell10.Align = "top";

                TextBox txtnewhecess = new TextBox();
                txtnewhecess.ID = TxtNewHeCessID[i].ToString();
                txtnewhecess.CssClass = "inputnumber";
                txtnewhecess.Enabled = false;
                cell10.Controls.Add(txtnewhecess);

                HtmlTableCell cell11 = new HtmlTableCell();
                cell11.Align = "top";

                TextBox txtnewcertificateno = new TextBox();
                txtnewcertificateno.ID = TxtNewCertificateNoID[i].ToString();
                txtnewcertificateno.CssClass = "inputnumber";
                cell11.Controls.Add(txtnewcertificateno);


                HtmlTableCell cell12 = new HtmlTableCell();
                cell12.Align = "top";

                TextBox txtnewreceiveddate = new TextBox();
                txtnewreceiveddate.ID = TxtNewReceivedDateID[i].ToString();
                txtnewreceiveddate.CssClass = "input";
                txtnewreceiveddate.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.id, event);");
                cell12.Controls.Add(txtnewreceiveddate);

                CalendarExtender calReceivedDate = new CalendarExtender();
                calReceivedDate.ID = CalReceivedDateID[i].ToString();
                calReceivedDate.PopupButtonID = txtnewreceiveddate.ID.ToString();
                calReceivedDate.TargetControlID = txtnewreceiveddate.ID.ToString();
                calReceivedDate.Format = "dd'/'MM''/yyyy";

                cell12.Controls.Add(calReceivedDate);

                HtmlTableCell cell13 = new HtmlTableCell();
                cell13.Align = "top";

                TextBox txtnewremarks = new TextBox();
                txtnewremarks.ID = TxtNewRemarksID[i].ToString();
                txtnewremarks.CssClass = "input";
                cell13.Controls.Add(txtnewremarks);

                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                row.Cells.Add(cell3);
                row.Cells.Add(cell4);
                row.Cells.Add(cell5);
                row.Cells.Add(cell6);
                row.Cells.Add(cell7);
                row.Cells.Add(cell8);
                row.Cells.Add(cell9);
                row.Cells.Add(cell10);
                row.Cells.Add(cell11);
                row.Cells.Add(cell12);
                row.Cells.Add(cell13);
                tblParticularService.Rows.Add(row);
                
            }
         
        }
    }
    protected void AddNewRow()
    {
        rowcount++;
        ControlCounter.Add(rowcount.ToString());

        HtmlTableRow row = new HtmlTableRow();

        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "top";

        DropDownList ddlparticular = new DropDownList();
        ddlparticular.ID = "ddlparticular" + rowcount.ToString();
        ddlparticular.CssClass = "dropdown";
        //ddlparticular.Width = Unit.Pixel(75);
        ddlparticular.AutoPostBack = true;
        BindParticulars(ddlparticular);
        ddlparticular.SelectedIndexChanged += new EventHandler(ddlparticular_SelectedIndexChanged);
        DdlParticularID.Add(ddlparticular.ID);
        cell1.Controls.Add(ddlparticular);

        HiddenField hidReferenceId = new HiddenField();
        hidReferenceId.ID = "hidReferenceId" + rowcount.ToString();
        hidReferenceID.Add(hidReferenceId.ID);
        cell1.Controls.Add(hidReferenceId);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "top";

        DropDownList ddlservice = new DropDownList();
        ddlservice.ID = "ddlservice" + rowcount.ToString();
        ddlservice.AutoPostBack = true;
        //ddlservice.Width = Unit.Pixel(75);
        ddlservice.CssClass = "dropdown";

        ddlservice.Attributes.Add("onchange", "return checkItemRepetion(this.id);");
        ddlservice.SelectedIndexChanged += new EventHandler(ddlparticular_SelectedIndexChanged);
        DdlServiceID.Add(ddlservice.ID);
        cell2.Controls.Add(ddlservice);

        HiddenField hidRefTranId = new HiddenField();
        hidRefTranId.ID = "hidRefTranId" + rowcount.ToString();
        hidRefTranID.Add(hidRefTranId.ID);
        cell2.Controls.Add(hidRefTranId);

        HiddenField hidRefChildId = new HiddenField();
        hidRefChildId.ID = "hidRefChildId" + rowcount.ToString();
        hidRefChildID.Add(hidRefChildId.ID);
        cell2.Controls.Add(hidRefChildId);

        HtmlInputHidden hidAddDesc = new HtmlInputHidden();
        hidAddDesc.ID = "hidAddDesc" + rowcount.ToString();
        hidAddDescID.Add(hidAddDesc.ID);
        cell2.Controls.Add(hidAddDesc);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "top";

        TextBox txtnewbalamount = new TextBox();
        txtnewbalamount.ID = "txtnewbalamount" + rowcount.ToString();
        txtnewbalamount.CssClass = "inputnumber";
        txtnewbalamount.Enabled = false;
        TxtNewBalAmountID.Add(txtnewbalamount.ID);
        cell3.Controls.Add(txtnewbalamount);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "top";

        TextBox txtnewtdsamount = new TextBox();
        txtnewtdsamount.ID = "txtnewtdsamount" + rowcount.ToString();
        txtnewtdsamount.Attributes.Add("OnKeyPress", "return isNumberKey(this.id, event); checkserviceselect(this.id);");
        txtnewtdsamount.Attributes.Add("onblur","calculate(); calculateTotalAmount();");
        txtnewtdsamount.CssClass = "inputnumber";
        txtnewtdsamount.Text = "0.00";
        TxtNewTdsAmountID.Add(txtnewtdsamount.ID.ToString());
        cell4.Controls.Add(txtnewtdsamount);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "top";

        TextBox txtnewstrate = new TextBox();
        txtnewstrate.ID = "txtnewstrate" + rowcount.ToString();
        txtnewstrate.CssClass = "inputnumber";
        txtnewstrate.Enabled = false;
        TxtNewStRateID.Add(txtnewstrate.ID.ToString());
        cell5.Controls.Add(txtnewstrate);

        HtmlTableCell cell6 = new HtmlTableCell();
        cell6.Align = "top";

        TextBox txtnewpecessrate = new TextBox();
        txtnewpecessrate.ID = "txtnewpecessrate" + rowcount.ToString();
        txtnewpecessrate.CssClass = "inputnumber";
        txtnewpecessrate.Enabled = false;
        TxtNewPeCessRateID.Add(txtnewpecessrate.ID.ToString());
        cell6.Controls.Add(txtnewpecessrate);

        HtmlTableCell cell7 = new HtmlTableCell();
        cell7.Align = "top";

        TextBox txtnewhecessrate = new TextBox();
        txtnewhecessrate.ID = "txtnewhecessrate" + rowcount.ToString();
        txtnewhecessrate.CssClass = "inputnumber";
        txtnewhecessrate.Enabled = false;
        TxtNewHeCessRateID.Add(txtnewhecessrate.ID.ToString());
        cell7.Controls.Add(txtnewhecessrate);

        HtmlTableCell cell8 = new HtmlTableCell();
        cell8.Align = "top";

        TextBox txtnewservicetax = new TextBox();
        txtnewservicetax.ID = "txtnewservicetax" + rowcount.ToString();
        txtnewservicetax.CssClass = "inputnumber";
        txtnewservicetax.Enabled = false;
        TxtNewServiceTaxID.Add(txtnewservicetax.ID.ToString());
        cell8.Controls.Add(txtnewservicetax);

        HtmlTableCell cell9 = new HtmlTableCell();
        cell9.Align = "top";

        TextBox txtnewpecess = new TextBox();
        txtnewpecess.ID = "txtnewpecess" + rowcount.ToString();
        txtnewpecess.CssClass = "inputnumber";
        txtnewpecess.Enabled = false;
        TxtNewPeCessID.Add(txtnewpecess.ID.ToString());
        cell9.Controls.Add(txtnewpecess);

        HtmlTableCell cell10 = new HtmlTableCell();
        cell10.Align = "top";

        TextBox txtnewhecess = new TextBox();
        txtnewhecess.ID = "txtnewhecess" + rowcount.ToString();
        txtnewhecess.CssClass = "inputnumber";
        txtnewhecess.Enabled = false;
        TxtNewHeCessID.Add(txtnewhecess.ID.ToString());
        cell10.Controls.Add(txtnewhecess);

        HtmlTableCell cell11 = new HtmlTableCell();
        cell11.Align = "top";

        TextBox txtnewcertificateno = new TextBox();
        txtnewcertificateno.ID = "txtnewcertificateno" + rowcount.ToString();
        txtnewcertificateno.CssClass = "inputnumber";
        TxtNewCertificateNoID.Add(txtnewcertificateno.ID.ToString());
        cell11.Controls.Add(txtnewcertificateno);


        HtmlTableCell cell12 = new HtmlTableCell();
        cell12.Align = "top";

        TextBox txtnewreceiveddate = new TextBox();
        txtnewreceiveddate.ID = "txtnewreceiveddate" + rowcount.ToString();
        txtnewreceiveddate.CssClass = "input";
        txtnewreceiveddate.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.id, event);");
        TxtNewReceivedDateID.Add(txtnewreceiveddate.ID.ToString());
        cell12.Controls.Add(txtnewreceiveddate);

        CalendarExtender calReceivedDate = new CalendarExtender();
        calReceivedDate.ID = "calReceivedDate" + rowcount.ToString();
        calReceivedDate.PopupButtonID = txtnewreceiveddate.ID.ToString();
        calReceivedDate.TargetControlID = txtnewreceiveddate.ID.ToString();
        calReceivedDate.Format = "dd'/'MM''/yyyy";
        CalReceivedDateID.Add(calReceivedDate.ID.ToString());
        cell12.Controls.Add(calReceivedDate);

        HtmlTableCell cell13 = new HtmlTableCell();
        cell13.Align = "top";

        TextBox txtnewremarks = new TextBox();
        txtnewremarks.ID = "txtnewremarks" + rowcount.ToString();
        txtnewremarks.CssClass = "input";
        TxtNewRemarksID.Add(txtnewremarks.ID.ToString());
        cell13.Controls.Add(txtnewremarks);

        row.Cells.Add(cell1);
        row.Cells.Add(cell2);
        row.Cells.Add(cell3);
        row.Cells.Add(cell4);
        row.Cells.Add(cell5);
        row.Cells.Add(cell6);
        row.Cells.Add(cell7);
        row.Cells.Add(cell8);
        row.Cells.Add(cell9);
        row.Cells.Add(cell10);
        row.Cells.Add(cell11);
        row.Cells.Add(cell12);
        row.Cells.Add(cell13);

        tblParticularService.Rows.Add(row);
        fillEmptyRow();
        hidControlCounter.Value = rowcount.ToString();
      

        ViewState["hidReferenceID"] = hidReferenceID;
        ViewState["hidRefTranID"] = hidRefTranID;
        ViewState["hidRefChildID"] = hidRefChildID;
        ViewState["hidAddDescID"] = hidAddDescID;
        ViewState["ControlCounter"] = ControlCounter;
        ViewState["DdlParticularID"] = DdlParticularID;
        ViewState["DdlServiceID"] = DdlServiceID;
        ViewState["TxtNewBalAmountID"] = TxtNewBalAmountID;
        ViewState["TxtNewTdsAmountID"] = TxtNewTdsAmountID;
        ViewState["TxtNewStRateID"] = TxtNewStRateID;
        ViewState["TxtNewPeCessRateID"] = TxtNewPeCessRateID;
        ViewState["TxtNewHeCessRateID"] = TxtNewHeCessRateID;
        ViewState["TxtNewServiceTaxID"] = TxtNewServiceTaxID;
        ViewState["TxtNewPeCessID"] = TxtNewPeCessID;
        ViewState["TxtNewHeCessID"] = TxtNewHeCessID;
        ViewState["TxtNewCertificateNoID"] = TxtNewCertificateNoID;
        ViewState["TxtNewReceivedDateID"] = TxtNewReceivedDateID;
        ViewState["CalReceivedDateID"] = CalReceivedDateID;
        ViewState["TxtNewRemarksID"] = TxtNewRemarksID;
        
    }
    protected void btnAddMore_Click(Object sender, EventArgs e)
    {
        AddNewRow();
    }
    protected void ddlreccustomer_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillGridForDetail();
    }

    protected void btn_save_Click(Object sender, EventArgs e)
    {
        try
        {
            using (TransactionScope scope = new TransactionScope())
            {
                _SaveVouchers_Details(_SaveVouchers());
                scope.Complete();               
            }
            Response.Redirect("TDSManagement.aspx?status=insert");
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
    protected void btn_cancel_Click(Object sender, EventArgs e)
    {
        Response.Redirect("TDSManagement.aspx");
    }

    private string _SaveVouchers()
    {
       
        try
        {
            string strTranId = string.Empty;
            string strTranDate = string.Empty;
            string strTranTypeId = string.Empty;
            if (TxtDate.Text != string.Empty)
            {
                string[] strTemp = TxtDate.Text.Split('/');
                strTranDate = strTemp[1] + "/" + strTemp[0] + "/" + strTemp[2];
            }
            SqlParameter[] sparam1 = 
                                {
                                    new SqlParameter("@TransactionTypeID","12"),      
                                    new SqlParameter("@TransactionNumber",TxtTdsNo.Text.Trim()),      
                                    new SqlParameter("@FinYear",Session["FINYEAR"].ToString()),      
                                    new SqlParameter("@ReferenceNumber",TxtRefNo.Text.Trim()),     
                                    new SqlParameter("@IsCashVoucher","0"),      
                                    new SqlParameter("@TransactionDate",strTranDate),      
                                    new SqlParameter("@Narration",""),     
                                    new SqlParameter("@CreditDays","0"),  
                                    new SqlParameter("@ChequeNumber","0"),
                                    new SqlParameter("@CreatedBy",Session["userid"].ToString()),      
                                    new SqlParameter("@IsCancelled","0"),    
                                    new SqlParameter("@CostCentreClassID","0")
                                };
            DU.executeprocedure("USP_ACC_SaveTransaction", sparam1);

            string strsql = "Select Ident_Current('ACC_VOUCHERS') as TranId";
            DataTable DTTranId = DU.getdata(strsql);
            if (DTTranId.Rows.Count > 0)
            {
                hidVoucherTranID.Value = DTTranId.Rows[0]["TranId"].ToString();
                strTranId = DTTranId.Rows[0]["TranId"].ToString();
              
            }
            return strTranId;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void  _SaveVouchers_Details(string strTranId)
    {
     
        string strTranDate = string.Empty;
        try
        {
            if (strTranId != string.Empty)
            {
                if (TxtDate.Text != string.Empty)
                {
                    string[] strTemp = TxtDate.Text.Split('/');
                    strTranDate = strTemp[1] + "/" + strTemp[0] + "/" + strTemp[2];
                }
                if (ddlCustomer.SelectedValue != "0")
                {
                    SqlParameter[] sparam =
                                                {
                                                    new SqlParameter("@TransactionId",Convert.ToInt32(strTranId)),
                                                    new SqlParameter("@LedgerId",ddlCustomer.SelectedValue),
                                                    new SqlParameter("@Amount",hidTotalAmount.Value.ToString()),
                                                    new SqlParameter("@IsReconciled","0"),
                                                    new SqlParameter("@ReconciledDate",strTranDate),
                                                    new SqlParameter("@ReconciledRemaks",""),
                                                    new SqlParameter("@Narration","")
                                                };
                    int result = DU.executeprocedure("USP_ACC_SaveTransactionDetails", sparam);                  
                    string strsql = "Select Ident_Current('ACC_VOUDETAILS') as VouSerial";
                    DataTable DT = DU.getdata(strsql);
                    if (DT.Rows.Count > 0)
                    {
                        _SaveReference_Details(DT.Rows[0]["VouSerial"].ToString());                      

                    }
                }
            }

            double tdsAmount = 0.00;
            tdsAmount = 0 - Convert.ToDouble(hidTotalAmount.Value.ToString());

                SqlParameter[] sparam2 =
                                            {
                                                new SqlParameter("@TransactionId",strTranId),
                                                new SqlParameter("@LedgerId",ddlCustomer.SelectedValue),
                                                new SqlParameter("@Amount",tdsAmount),
                                                new SqlParameter("@IsReconciled","0"),
                                                new SqlParameter("@ReconciledDate",strTranDate),
                                                new SqlParameter("@ReconciledRemaks",""),
                                                new SqlParameter("@Narration","")
                                            };
                DU.executeprocedure("USP_ACC_SaveTransactionDetails", sparam2);
            
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveReference_Details(string strVouSerial)
    {
        try
        {
            if (strVouSerial != string.Empty)
            {
                string strRefDate = string.Empty;
                string strRefferenceNo = string.Empty;
                if (TxtDate.Text.ToString() != string.Empty)
                {
                    string[] str = TxtDate.Text.ToString().Split('/');
                    strRefDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
                }
                int rowCount = Convert.ToInt32(hidControlCounter.Value);
                for (int i = 1; i <= rowCount; i++)
                {
                    DropDownList ddlParticular = (DropDownList)tblParticularService.Rows[i].FindControl("ddlParticular" + i);
                    TextBox texnewtdsAmount = (TextBox)tblParticularService.Rows[i].FindControl("txtnewtdsAmount" + i);

                    SqlParameter[] sparam = {
                                            new SqlParameter("@ReferenceSerial","0"),
                                            new SqlParameter("@ParentReference",ddlParticular.SelectedValue),
                                            new SqlParameter("@TransactionSerial",Convert.ToInt32(strVouSerial)),
                                            new SqlParameter("@ReferenceType","2"),
                                            new SqlParameter("@Reference",ddlParticular.SelectedItem.Text),
                                            new SqlParameter("@ReferenceDate",strRefDate),
                                            new SqlParameter("@CreditDays","0"),
                                            new SqlParameter("@ReferenceAmount",texnewtdsAmount.Text.Trim()),
                                            new SqlParameter("@IsTDSDeducted","0"),
                                            new SqlParameter("@OutstandingRemarks","")
                                                
                                };
                    int result = DU.executeprocedure("USP_ACC_SaveReferenceDetails", sparam);
                        if(result>0)
                                    {
                                      _SaveTDSManagement_Main();
                                     } 
                   
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveTDSManagement_Main()
    {       
        try
        {

            if (hidVoucherTranID.Value.ToString() != string.Empty)
            {
                SqlParameter[] sqlparaInsert1 = {
                                        new SqlParameter("@TDSMANAGEMENTID","0"),
                                        new SqlParameter("@TRANSACTIONID",hidVoucherTranID.Value.ToString()),
                                        new SqlParameter("@CUSTOMERLEDGERID",ddlCustomer.SelectedValue) 
                                      };
                int result = DU.executeprocedure("USP_IVC_SaveTDSManagement", sqlparaInsert1);
                
                string strsql = "select ident_current('IVC_TDSManagement_Main') as TDSMainID";
                DataTable dtTDSMain = DU.getdata(strsql);
                if (dtTDSMain.Rows.Count > 0)
                {
                    _SaveTDSManagement_CHILD(dtTDSMain.Rows[0]["TDSMainID"].ToString());
                   
                }
            }            

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void _SaveTDSManagement_CHILD(string TDSMAINID)
    {
        try
        {
            if (TDSMAINID != string.Empty)
            {
                int count = Convert.ToInt32(hidControlCounter.Value.ToString());
                for (int j = 1; j <= count; j++)
                {
                    DropDownList ddlparticular = (DropDownList)tblParticularService.Rows[j].FindControl("ddlparticular" + j);
                    HiddenField hidRefrnceid = (HiddenField)tblParticularService.Rows[j].FindControl("hidReferenceId" + j);
                    DropDownList ddlservice = (DropDownList)tblParticularService.Rows[j].FindControl("ddlservice" + j);
                    HiddenField hidRfTranId = (HiddenField)tblParticularService.Rows[j].FindControl("hidRefTranId" + j);
                    HiddenField hidRfChildId = (HiddenField)tblParticularService.Rows[j].FindControl("hidRefChildId" + j);
                    TextBox txtnewbalamount = (TextBox)tblParticularService.Rows[j].FindControl("txtnewbalamount" + j);
                    TextBox txtnewtdsamount = (TextBox)tblParticularService.Rows[j].FindControl("txtnewtdsamount" + j);
                    TextBox txtnewstrate = (TextBox)tblParticularService.Rows[j].FindControl("txtnewstrate" + j);
                    TextBox txtnewpecessrate = (TextBox)tblParticularService.Rows[j].FindControl("txtnewpecessrate" + j);
                    TextBox txtnewhecessrate = (TextBox)tblParticularService.Rows[j].FindControl("txtnewhecessrate" + j);
                    TextBox txtnewservicetax = (TextBox)tblParticularService.Rows[j].FindControl("txtnewservicetax" + j);
                    TextBox txtnewpecess = (TextBox)tblParticularService.Rows[j].FindControl("txtnewpecess" + j);
                    TextBox txtnewhecess = (TextBox)tblParticularService.Rows[j].FindControl("txtnewhecess" + j);
                    TextBox txtnewcertificateno = (TextBox)tblParticularService.Rows[j].FindControl("txtnewcertificateno" + j);
                    TextBox txtnewreceiveddate = (TextBox)tblParticularService.Rows[j].FindControl("txtnewreceiveddate" + j);
                    TextBox txtnewremarks = (TextBox)tblParticularService.Rows[j].FindControl("txtnewremarks" + j);

                    SqlParameter[] sqlparaInsert2 = {
                                                   new SqlParameter("@TDSMANAGEMENTCHILDID","0"),      
                                                   new SqlParameter("@TDSMANAGEMENTID",Convert.ToInt32(TDSMAINID)),      
                                                   new SqlParameter("@REFERENCETRANID",hidRfTranId.Value.ToString()),      
                                                   new SqlParameter("@REFERENCECHILDID",hidRfChildId.Value.ToString()),      
                                                   new SqlParameter("@REFERENCEID",hidRefrnceid.Value.ToString()),      
                                                   new SqlParameter("@SERVICEID",ddlservice.SelectedValue),      
                                                   new SqlParameter("@AMOUNT",txtnewtdsamount.Text.Trim()),      
                                                   new SqlParameter("@CESS1RATE",txtnewpecessrate.Text.Trim()),      
                                                   new SqlParameter("@CESS1AMT",txtnewpecess.Text.Trim()),      
                                                   new SqlParameter("@CESS2RATE",txtnewhecessrate.Text.Trim()),      
                                                   new SqlParameter("@CESS2AMT",txtnewhecess.Text.Trim()),
                                                   new SqlParameter("@SERVICERATE",txtnewstrate.Text.Trim()), 
                                                   new SqlParameter("@SERVICEAMT",txtnewservicetax.Text.Trim()),
                                                   new SqlParameter("@TDSTAXABLEAMT",txtnewbalamount.Text.Trim()),
                                                   new SqlParameter("@ABATEMENTAMT","0"),
                                                   new SqlParameter("@SERVICECHARGEAMT","0")
                                             };
                    int result = DU.executeprocedure("USP_IVC_SaveTDSManagementService", sqlparaInsert2);                    
                    string strsql = "select ident_current('IVC_TDSMANAGEMENT_CHILD') as TDSChildID";
                    DataTable dtTDSChild = DU.getdata(strsql);
                    if (dtTDSChild.Rows.Count > 0)
                    {
                        string strRefDateRece = string.Empty;
                        if (txtnewreceiveddate.Text.ToString() != string.Empty)
                        {
                            string[] str = TxtDate.Text.ToString().Split('/');
                            strRefDateRece = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
                        }
                        SqlParameter[] sqlInsertCertificate = {
                                                   new SqlParameter("@CERTIFICATEID","0"),      
                                                   new SqlParameter("@REFERENCETRANID",hidRefrnceid.Value.ToString()),      
                                                   new SqlParameter("@REFERENCECHILDID",Convert.ToInt32(dtTDSChild.Rows[0]["TDSChildID"].ToString())),      
                                                   new SqlParameter("@CERTIFICATENUMBER",txtnewcertificateno.Text.Trim()),      
                                                   new SqlParameter("@RECEIVEDDATE",strRefDateRece),
                                                   new SqlParameter("@REMARKS",txtnewremarks.Text.Trim())
                                                            };
                        int resultd = DU.executeprocedure("USP_IVC_SaveTDSCertificate", sqlInsertCertificate);
                       
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void Tabs_ActiveTabChanged(object sender, EventArgs e)
    {

    }

}